﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web;
using System.Data;
using System.Configuration;


public partial class admin_sell_property : System.Web.UI.Page
{
    string c_id = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["email"] == null)
        {
            Response.Redirect("sessiont.aspx");
        }
        Label2.Text = Session["email"].ToString();
        Session["proptype"] = DropDownList6.SelectedValue;
        Label9.Text = Session["proptype"].ToString();



    }




    protected void Cancel_Click(object sender, System.EventArgs e)
    {
        //btnSave_Student.Visible = true;
    }




    protected void Save_Click(object sender, System.EventArgs e)
    {

        string cat = null;
        cat = DropDownList1.SelectedValue;



        SqlConnection conn = null;

        conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
        conn.Open();


        if (cat.Equals("Yes"))
        {

            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            c_id = letter + number; // join both as ID 

            string p_size = TextBox11.Text + DropDownList7.SelectedValue;

            string balcony = DropDownList14.SelectedValue + TextBox6.Text;
            SqlCommand cmd = new SqlCommand("Insert into property_buy values(@p_id ,@type,@wants_to,@property,@c_type,@agent_name,@client_fullname,@property_type,@house_no,@city,@street,@ssn,@zip,@country,@email_id,@phone,@room_no,@floor,@store,@ac,@parking,@elevator,@price,@prop_size,@entering_date,@condtion,@balconies,@a_hours,@safe_room,@budget,@purpose,@nghrhood,@comment,@financing,@custom_name,@category,@c_cat,@cat,@adding_by,@date,@status)", conn);




            cmd.Parameters.AddWithValue("@p_id", c_id);
            cmd.Parameters.AddWithValue("@type", DropDownList5.SelectedValue);
            cmd.Parameters.AddWithValue("@wants_to", "To Buy");
            cmd.Parameters.AddWithValue("@property", DropDownList20.SelectedValue);

            cmd.Parameters.AddWithValue("@c_type", DropDownList20.SelectedValue);
            cmd.Parameters.AddWithValue("@agent_name", DropDownList15.SelectedValue);

            cmd.Parameters.AddWithValue("@client_fullname", txtmname.Text);
            cmd.Parameters.AddWithValue("@property_type", Session["proptype"]);
            cmd.Parameters.AddWithValue("@house_no", txthno.Text);
            cmd.Parameters.AddWithValue("@city", txtcity.Text);
            cmd.Parameters.AddWithValue("@street", txtstreet.Text);
            cmd.Parameters.AddWithValue("@ssn", txtssn.Text);
            cmd.Parameters.AddWithValue("@zip", txtzip.Text);
            cmd.Parameters.AddWithValue("@country", txtcountry.Text);
            cmd.Parameters.AddWithValue("@email_id", txtemail.Text);
            cmd.Parameters.AddWithValue("@phone", txtphno.Text);
            cmd.Parameters.AddWithValue("@room_no", TextBox3.Text);

            cmd.Parameters.AddWithValue("@floor", TextBox4.Text);
            cmd.Parameters.AddWithValue("@store", TextBox5.Text);

            cmd.Parameters.AddWithValue("@ac", DropDownList16.Text);
            cmd.Parameters.AddWithValue("@parking", TextBox7.Text);
            cmd.Parameters.AddWithValue("@elevator", TextBox8.Text);
            cmd.Parameters.AddWithValue("@price", TextBox9.Text);
            cmd.Parameters.AddWithValue("@prop_size", p_size);


            cmd.Parameters.AddWithValue("@entering_date", TextBox12.Text);
            cmd.Parameters.AddWithValue("@condtion", "none");


            cmd.Parameters.AddWithValue("@balconies", balcony);

            cmd.Parameters.AddWithValue("@a_hours", TextBox10.Text);
            cmd.Parameters.AddWithValue("@safe_room", TextBox15.Text);
            cmd.Parameters.AddWithValue("@budget", TextBox16.Text);
            cmd.Parameters.AddWithValue("@purpose", DropDownList17.SelectedValue);


            cmd.Parameters.AddWithValue("@nghrhood", TextBox18.Text);
            cmd.Parameters.AddWithValue("@comment", TextBox13.Text);
            cmd.Parameters.AddWithValue("@financing", DropDownList18.SelectedValue);
            cmd.Parameters.AddWithValue("@custom_name", DropDownList19.SelectedValue);
            cmd.Parameters.AddWithValue("@category", ddlcategory.SelectedValue);
            cmd.Parameters.AddWithValue("@c_cat", DropDownList1.SelectedValue);
            cmd.Parameters.AddWithValue("@cat", txtcatname.Text);
            cmd.Parameters.AddWithValue("@adding_by", Session["email"]);
            cmd.Parameters.AddWithValue("@date", System.DateTime.Now);
            cmd.Parameters.AddWithValue("@status", "1");
            cmd.ExecuteNonQuery();


            //SqlCommand cmd1 = new SqlCommand("Insert into client_add1 values(@c_id ,@f_name,@type_,@status1)", conn);
            //cmd1.Parameters.AddWithValue("@c_id", c_id);
            //cmd1.Parameters.AddWithValue("@f_name", txtmname.Text);
            //cmd1.Parameters.AddWithValue("@type_", DropDownList4.SelectedValue);

            //cmd1.Parameters.AddWithValue("@status1", "0");
            //cmd1.ExecuteNonQuery();


            Session["c_id"] = c_id;
            Response.Redirect("client_confirmation.aspx");

        }
        else
        {

            Random r1 = new Random();
            int num = r1.Next(0, 99999999); // generate random number
            string number = string.Format("{0:D8}", num);

            Random r2 = new Random();
            int num2 = r2.Next(0, 26); // generate random letter
            char letter = (char)('A' + num2);


            c_id = letter + number; // join both as ID 
            string p_size = TextBox11.Text + DropDownList7.SelectedValue;

            string balcony = DropDownList14.SelectedValue + TextBox6.Text;
            SqlCommand cmd = new SqlCommand("Insert into property_buy values(@p_id,@type,@wants_to,@property,@c_type,@agent_name,@client_fullname,@property_type,@house_no,@city,@street,@ssn,@zip,@country,@email_id,@phone,@room_no,@floor,@store,@ac,@parking,@elevator,@price,@prop_size,@entering_date,@condtion,@balconies,@a_hours,@safe_room,@budget,@purpose,@nghrhood,@comment,@financing,@custom_name,@category,@c_cat,@cat,@adding_by,@date,@status)", conn);




            cmd.Parameters.AddWithValue("@p_id", c_id);
            cmd.Parameters.AddWithValue("@type", DropDownList5.SelectedValue);
            cmd.Parameters.AddWithValue("@wants_to", "To Sell");
            cmd.Parameters.AddWithValue("@property", DropDownList20.SelectedValue);
            cmd.Parameters.AddWithValue("@c_type", DropDownList20.SelectedValue);
            cmd.Parameters.AddWithValue("@agent_name", DropDownList15.SelectedValue);
            cmd.Parameters.AddWithValue("@client_fullname", txtmname.Text);
            cmd.Parameters.AddWithValue("@property_type", Session["proptype"]);
            cmd.Parameters.AddWithValue("@house_no", txthno.Text);
            cmd.Parameters.AddWithValue("@city", txtcity.Text);
            cmd.Parameters.AddWithValue("@street", txtstreet.Text);
            cmd.Parameters.AddWithValue("@ssn", txtssn.Text);
            cmd.Parameters.AddWithValue("@zip", txtzip.Text);
            cmd.Parameters.AddWithValue("@country", txtcountry.Text);
            cmd.Parameters.AddWithValue("@email_id", txtemail.Text);
            cmd.Parameters.AddWithValue("@phone", txtphno.Text);
            cmd.Parameters.AddWithValue("@room_no", TextBox3.Text);

            cmd.Parameters.AddWithValue("@floor", TextBox4.Text);
            cmd.Parameters.AddWithValue("@store", TextBox5.Text);

            cmd.Parameters.AddWithValue("@ac", DropDownList16.Text);
            cmd.Parameters.AddWithValue("@parking", TextBox7.Text);
            cmd.Parameters.AddWithValue("@elevator", TextBox8.Text);
            cmd.Parameters.AddWithValue("@price", TextBox9.Text);
            cmd.Parameters.AddWithValue("@prop_size", p_size);


            cmd.Parameters.AddWithValue("@entering_date", TextBox12.Text);
            cmd.Parameters.AddWithValue("@condtion", "none");


            cmd.Parameters.AddWithValue("@balconies", balcony);

            cmd.Parameters.AddWithValue("@a_hours", TextBox10.Text);
            cmd.Parameters.AddWithValue("@safe_room", TextBox15.Text);
            cmd.Parameters.AddWithValue("@budget", TextBox16.Text);
            cmd.Parameters.AddWithValue("@purpose", DropDownList17.SelectedValue);


            cmd.Parameters.AddWithValue("@nghrhood", TextBox18.Text);
            cmd.Parameters.AddWithValue("@comment", TextBox13.Text);
            cmd.Parameters.AddWithValue("@financing", DropDownList18.SelectedValue);
            cmd.Parameters.AddWithValue("@custom_name", DropDownList19.SelectedValue);
            cmd.Parameters.AddWithValue("@category", ddlcategory.SelectedValue);
            cmd.Parameters.AddWithValue("@c_cat", DropDownList1.SelectedValue);
            cmd.Parameters.AddWithValue("@cat", "no");
            cmd.Parameters.AddWithValue("@adding_by", Session["email"]);
            cmd.Parameters.AddWithValue("@date", System.DateTime.Now);
            cmd.Parameters.AddWithValue("@status", "1");
            cmd.ExecuteNonQuery();

            SqlCommand cmd1 = new SqlCommand("Insert into client_add1 values(@c_id ,@f_name,@type_,@status1)", conn);
            cmd1.Parameters.AddWithValue("@c_id", c_id);
            cmd1.Parameters.AddWithValue("@f_name", txtmname.Text);
            cmd1.Parameters.AddWithValue("@type_", DropDownList20.SelectedValue);

            cmd1.Parameters.AddWithValue("@status1", "0");
            cmd1.ExecuteNonQuery();
            Session["c_id"] = c_id;
            Response.Redirect("client_confirmation.aspx");


        }
        conn.Close();


    }
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
    protected void DropDownList4_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        
    }

    protected void Save1_Click(object sender, System.EventArgs e)
    {

    }
}